package com.ruoyi.system.generator;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.core.enums.SqlLike;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.engine.BeetlTemplateEngine;

import java.util.Collections;

public class Generator {

    private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
            .Builder("jdbc:mysql://39.99.46.17:7506/tieta?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8", "root", "abc12#");

    public static void main(String[] args) {
        FastAutoGenerator.create(DATA_SOURCE_CONFIG)
                .globalConfig(builder -> {
                    builder.author("liusha") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://testplus"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.ruoyi") // 设置父包名
                            .moduleName("system") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://testplus")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.likeTable(new LikeTable("t_", SqlLike.RIGHT))
                            .addTablePrefix("t_"); // 设置过滤表前缀
                })
                .templateEngine(new BeetlTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
